

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Array;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;

/**
 * Servlet implementation class Test
 */
@WebServlet("/Test")
public class Test extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Test() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession(true);
		
		ResultSet rs = null;
		PrintWriter out = response.getWriter();
		try {
			Database data = new Database();
			data.Select("ADDRESS, RESOURSES, INCOME");
			data.From("INCOME_POSITION");
			rs = data.GetResult();
			ResultSetMetaData temp = rs.getMetaData();
			ArrayList<Integer> Address = new ArrayList<>();
			ArrayList<Integer> Resources = new ArrayList<>();
			ArrayList<Double> Income = new ArrayList<>();
			while(rs.next()){
				Address.add(rs.getInt(1));
				Resources.add(rs.getInt(2));
				Income.add(rs.getDouble(3));
			}
			request.setAttribute("Address", Address);
			request.setAttribute("Resources", Resources);
			request.setAttribute("Income", Income);
			
			request.getRequestDispatcher(response.encodeURL("index.jsp")).forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
